package binarytree

func kthSmallest(root *TreeNode, k int) int {

	nums := []int{}

	var dfs func(*TreeNode)
	dfs = func(root *TreeNode) {
		if root == nil {
			return
		}
		dfs(root.Left)
		nums = append(nums, root.Val)
		dfs(root.Right)
	}

	dfs(root)

	return nums[k]

}
